﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Traceability.Writer.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UpLoadController : ControllerBase
    {

        private readonly IMediator mediator;

        public UpLoadController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        [HttpPost]
        public async Task<dynamic> UploadImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/Files/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:5004/Files/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }


        }


        /// <summary>
        /// 上传动检图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<dynamic> UploadDynamicImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/DynamicFiles/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:5004/DynamicFiles/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }


        }

        //

        /// <summary>
        /// 企业照片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<dynamic> UploadCorporateImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/CorporateFiles/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:5004/CorporateFiles/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }


        }



        /// <summary>
        /// 相关资质照片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<dynamic> UploadQualificationsImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/QualificationsFiles/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:5004/QualificationsFiles/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }


        }


        /// <summary>
        /// 上传屠宰企业照片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<dynamic> UploadSlaughterFirmsFilesImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/SlaughterFirmsFiles/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:5004/SlaughterFirmsFiles/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }


        }


        /// <summary>
        /// 食品安全图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<dynamic> UploadProcessFirmsFilesImages(IFormFile file)
        {
            try
            {

                var res = "wwwroot/ProcessFiles/" + file.FileName;
                using (FileStream fs = new FileStream(res, FileMode.OpenOrCreate))
                {
                    file.CopyTo(fs);
                }

                return Ok("http://localhost:5004/ProcessFiles/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }


        }

    }
}
